package org.jsbd.boss.service.impl;

import org.jsbd.boss.dao.IBookDao;
import org.jsbd.boss.dao.IBookPayLogDao;
import org.jsbd.boss.domian.Book;
import org.jsbd.boss.domian.BookPayLog;
import org.jsbd.boss.service.IBookPayLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("bookPayLogService")
public class BookPayLogServiceImpl implements IBookPayLogService {

	@Autowired
	private IBookPayLogDao bookPayLogDao;

	@Autowired
	private IBookDao bookDao;

	@Transactional("transactionManagerCrack")
	@Override
	public void save(BookPayLog bookPayLog) {
		//冥等操作
		Integer count = bookPayLogDao.getCountByImsiMark(bookPayLog);
		if (count.intValue() == 0) {
			bookPayLogDao.save(bookPayLog);

			Book book = new Book();
			book.setMark(bookPayLog.getMark());
			book.setName(bookPayLog.getPayContent());

			Book bk = bookDao.getByMarkAndName(book);
			if (bk != null) {
				bk.setPayMoney(bookPayLog.getMoney());
				bookDao.updatePayMoneyById(bk);
			}
		}
	}

}
